<!--************************************************************************************************-->
<!-- < userPage.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder: Xiaoxin Mo                                                                 -->
<!-- Stu : 10389159                                                                                 -->
<!-- Date: 2012-01-01                                                                               -->
<!--                                                                                                -->
<!-- Version : 2.1                                                                                  -->
<!-- LastUpdate : 2013-01-01 14:30 BY Xiaoxin Mo                                                      -->
<!--************************************************************************************************-->


<!DOCTYPE html>
<?php
	//session_start();
	include_once("header.php");  // header里面已经调用session_start()
	//include_once("bottom.php");
	include_once("../manager/BookManager.php");
	include_once("../manager/ThesisManager.php");
	include_once("../manager/GroupManager.php");
	include_once("../manager/UserManager.php");
	include_once("../manager/FriendManager.php");
	include_once("../manager/NoteManager.php");
	include_once("../manager/CommentManager.php");
	
	$currentUser = $_REQUEST['user_name'];
	$currentID = UserManager::getInstance()->getIDByUsername($currentUser);
	// parameter $N to be modified
	$friendnames = FriendManager::getInstance()->getFriendnameByUsername($currentUser, 10);
	
	$is_friend = false;
	foreach($friendnames as $friend)
	{
		if (isset( $_SESSION['currentUser']))
			if ($friend === $_SESSION['currentUser'])
			{
				$is_friend = true;
			}
	}
?>
<html lang="zh-hk">
<head>

	<title>Tiny bOOk</title>
	
	<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
	<meta name="contentType" value="text/html  charset=GBK">
	<meta name="description" content="在这里你可以看到最新发布的书籍，和好友共享对某本书的评论和笔记">
	<meta http-equiv="imagetoolbar" content="no">
	<meta name="viewport" content="width=1036">
	
	<link rel="stylesheet" type="text/css" href="../css/myPage.css">
	<link rel="stylesheet" type="text/css" href="../css/userPage.css">
</head>

<body>
	<div id="main">
		<div id="right">
			<div id="myfriends">
				<p><?=$currentUser?>的好友：</p>
				<?php
					foreach($friendnames as $friend)
					{
				?>
						<p><a href="userPage.php?user_name=<?=$friend?>"><?=$friend?></a></p>
				<?php
					}
				?>				
			</div>
			<!-- 添加好友按钮调整一下位置 by xiaoxin -->	
			<?php
			if (isset( $_SESSION['currentUser']))
			{
				if ($_SESSION['currentUser'] != $currentUser)
				{
			?>
					<div id="myfriends">
						<?php
							if ($is_friend)
							{
						?>
								<input class="addfriend" type="submit" name="addfriend" value="互相关注"/>
						<?php
							}else
							{
						?>
								<form action="addFriendResult.php" enctype="multipart/form-data" method="post">
									<input type="hidden" name="username" size="10" value="<?=$currentUser?>"/>
									<input class="addfriend" type="submit" name="addfriend" value="添加好友"/>
								</form>
						<?php
							}
						?>
					</div>
			<?php
				}
			}
			?>
		</div>

		<div id="left">
			<div id="personal">
				<h2><?=$currentUser?>的个人主页</h2>
			</div>
			
			<div id="info">
			
				<div id="uploadbooks"  class="info_detail">
					<p><?=$currentUser?>上传的书籍：</p>
					<div class="content">
						<?php
						// get 4 books for the list
						$bookList = BookManager::getInstance()->getBooklistByUserID($currentID, 4);
						
						foreach ($bookList as $bookname)
						{
							// record the bookname so can get the value when clicking it 
							$_SESSION['currentBook'] = $bookname;
						?>
							<p><a href="bookPage.php?book_name=<?=$bookname?>"><?=$bookname?></a></p>
						<?php
						}
						?>
					</div>
				</div>
				<div id="uploadpapers"  class="info_detail">
					<p><?=$currentUser?>上传的论文：</p>
					<div class="content">
						<?php
						// get 4 theses for the list====================modified by xiaoxin
						$thesisList = ThesisManager::getInstance()->getThesisNamesByUserID($currentID, 4);
						
						foreach ($thesisList as $thesisname)
						{
							// record the bookname so can get the value when clicking it 
							$_SESSION['currentThesis'] = $thesisname;
						?>
							<p><a href="thesisPage.php?thesis_name=<?=$thesisname?>"><?=$thesisname?></a></p>
						<?php
						}
						?>
					</div>
				</div>
				<!--=========================modified by xiaoxin-->
				<div id="creategroups"  class="info_detail">
					<p><?=$currentUser?>的小组：</p>
					<div class="content">
						<?php
						// get 4 books for the list
						$groupNames = UserManager::getInstance()->getGrouplistByUsername($currentUser);
						
						foreach ($groupNames as $groupName)
						{
						?>
							<a href="groupPage.php?group_name=<?=$groupName?>" >
								<span><?=$groupName?></span>
							</a>
						<?php
						}
						?>
					</div>
				</div>
				
				<div id="comments"  class="info_detail">
					<p><?=$currentUser?>的评论：</p>
					
					<div class="content">
						<?php
						// get 4 books for the list
						$comments = CommentManager::getInstance()->getCommentlistByUsername($currentUser, 4);
						
						foreach ($comments as $comment)
						{
						?>
							<p><a href=""><?=$comment?></a></p>
						<?php
						}
						?>
					</div>
				</div>

				<?php
					if ($is_friend)
					{
				?>
						<div id="notes"  class="info_detail">
							<p><?=$currentUser?>的笔记：</p>
							<div class="content">
								<?php
								// get 4 books for the list
								$notes = NoteManager::getInstance()->getNotelistByUsername($currentUser, 4);

								foreach ($notes as $note)
								{
								?>
									<p><a href=""><?=$note?></a></p>
								<?php
								}
								?>
							</div>		
						</div>
				<?php
					}
				?>
			</div>
		</div>


		<!--<div id="bottom">
				<p>@2012 - 2014 by cat-fish,all rights reserves</p>
		</div>-->
	</div><!--end of main-->
</body>